{{- define "recommender_resources" }}
cpu: 25m
memory: 50Mi
{{- end }}
---
apiVersion: autoscaling.k8s.io/v1
kind: VerticalPodAutoscaler
metadata:
  name: vpa-recommender
  namespace: kube-system
  {{- include "helm_lib_module_labels" (list . (dict "app" "vpa-recommender")) | nindent 2 }}
spec:
  targetRef:
    apiVersion: "apps/v1"
    kind: Deployment
    name: vpa-recommender
  updatePolicy:
    updateMode: "Auto"
  resourcePolicy:
    containerPolicies:
    - containerName: "recommender"
      minAllowed:
        {{- include "recommender_resources" . | nindent 8 }}
      maxAllowed:
        cpu: 50m
        memory: 100Mi
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: vpa-recommender
  namespace: kube-system
  {{- include "helm_lib_module_labels" (list . (dict "app" "vpa-recommender")) | nindent 2 }}
spec:
  replicas: 1
  revisionHistoryLimit: 2
  selector:
    matchLabels:
      app: vpa-recommender
  template:
    metadata:
      labels:
        app: vpa-recommender
    spec:
      {{- include "helm_lib_priority_class" (tuple . "cluster-medium") | nindent 6 }}
      {{- include "helm_lib_node_selector" (tuple . "system") | nindent 6 }}
      {{- include "helm_lib_tolerations" (tuple . "system") | nindent 6 }}
      {{- include "helm_lib_module_pod_security_context_run_as_user_nobody" . | nindent 6 }}
      serviceAccountName: d8-vertical-pod-autoscaler-recommender
      imagePullSecrets:
      - name: deckhouse-registry
      containers:
      - name: recommender
        {{- include "helm_lib_module_container_security_context_read_only_root_filesystem" . | nindent 8 }}
        image: {{ include "helm_lib_module_image" (list . "recommender") }}
        command:
        - /recommender
        - --address=:8942
        - --kube-api-burst=100
        - --kube-api-qps=50
        - --pod-recommendation-min-cpu-millicores=25
        - --pod-recommendation-min-memory-mb=50
        - --memory-aggregation-interval=1h
        - --recommender-interval={{ printf "%vs" $.Values.global.discovery.prometheusScrapeInterval }}
        - --stderrthreshold=0
        - --v=4
        ports:
        - containerPort: 8080
        resources:
          requests:
            {{- include "helm_lib_module_ephemeral_storage_only_logs" . | nindent 12 }}
{{- if not ( .Values.global.enabledModules | has "vertical-pod-autoscaler-crd") }}
            {{- include "recommender_resources" . | nindent 12 }}
{{- end }}

